package com.yxt.qmgf.start.view;

import de.felixroske.jfxsupport.SplashScreen;
import javafx.scene.Parent;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;

import java.io.File;

public class WelcomeScreen extends SplashScreen {
    private static final String DEFAULT_IMAGE = "config/ui/welcome.png";
    private final boolean flag;

    public WelcomeScreen() {
        flag = new File(DEFAULT_IMAGE).exists();
    }

    @Override
    public Parent getParent() {

        if (!flag) {
            return super.getParent();
        }

        ImageView imageView = new ImageView("file:" + DEFAULT_IMAGE);
        // 设置图片的显示大小
        imageView.setFitWidth(600); // 设置图片宽度
        imageView.setFitHeight(400); // 设置图片高度
        //进度条
        final ProgressBar splashProgressBar = new ProgressBar();
        splashProgressBar.setPrefWidth(600);
        final VBox vbox = new VBox();
        vbox.getChildren().addAll(imageView, splashProgressBar);
        return vbox;
    }

    @Override
    public boolean visible() {
        return true;
    }

    @Override
    public String getImagePath() {
        if (!flag) {
            return super.getImagePath();
        }
        return DEFAULT_IMAGE;
    }
}
